package com.example.androidbighomework;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.androidbighomework.utils.SaveChangePersonInfo;

public class ChangePersonInfoActivity extends AppCompatActivity {

    private Button Save_info;//activity_change_person.xml里的保存修改按钮
    private EditText Et_change_name,Et_change_phone,Et_change_birth;//activity_change_person.xml三个编辑框


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_person_info);
        //初始化控件
        initView();
        //监听保存修改按钮的点击，获取在编辑框输入的内容，并完成保存到personinfos.xml文件，最后完成页面的关闭。
        Save_info.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String changename = Et_change_name.getText().toString().trim();
                String changephone = Et_change_phone.getText().toString().trim();
                String changebirth = Et_change_birth.getText().toString().trim();
                //调用utils的SaveChangePersonInfo里的保存信息方法
                boolean isSaveSuccess= SaveChangePersonInfo.savePersonInfo(ChangePersonInfoActivity.this,changename,changephone,changebirth);
                if (isSaveSuccess){
                    Toast.makeText(ChangePersonInfoActivity.this, "保存成功", Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(ChangePersonInfoActivity.this, "保存失败", Toast.LENGTH_SHORT).show();
                }
                //关闭页面
                finish();
            }
        });


    }
    //初始化控件
    private void initView() {
        Save_info=findViewById(R.id.saveInfo);

        Et_change_name=findViewById(R.id.et_change_name);
        Et_change_phone=findViewById(R.id.et_change_phone);
        Et_change_birth=findViewById(R.id.et_change_birth);


    }
}